import { Plugin } from '../../src/plugins/Plugin';

export class Demo1 extends Plugin<Plugin.All, { isDemo: boolean; keyword: string; }, { counter: number }> {
  public counter = 1;

  constructor() {
    super();
    this.use(async (ctx, next) => {
      this.counter++;
      ctx.keyword = '###';
      ctx.isDemo = true;
      ctx.state.counter = this.counter;
      await next();
    });
  }
}

export class Demo2 extends Plugin {
  public counter = 1;

  constructor() {
    super();
    this.use(async (_, next) => {
      this.counter++;
      await next();
    });
  }
}

export class Demo3 extends Plugin {
  public demo1 = new Demo1();
  public demo2 = new Demo1();
  public demo4 = new Demo1();
  public demo5 = new Demo1();
  public counter = 1;

  constructor() {
    super();
    this
      .use(this.demo1)
      .use(this.demo2)
      .use(this.demo4)
      .use((_, next) => {
        this.counter++;
        return next();
      })
      .use(this.demo5);
  }
}

export class Demo4 extends Plugin {
  public counter = 1;

  constructor() {
    super();
    this.expect(Demo1).use(async (ctx, next) => {
      ctx.keyword += '***';
      this.counter++;
      await next();
    });
  }
}
